package com.pro.springbootshop.controller;

import com.pro.springbootshop.entityExtend.CollectReturn;
import com.pro.springbootshop.service.CollectService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class CollectController {
    @Autowired
    CollectService collectService;
    @ApiOperation("添加商品到收藏")
    @PostMapping("/api/collect/{waresId}")
    public String addCollect(@PathVariable(name = "waresId") Integer waresId, HttpServletRequest request){
        String token = request.getHeader("token");
        return collectService.addCollect(waresId,token);
    }
    @ApiOperation("获取所有收藏")
    @GetMapping("/api/collect/{page}/{limit}")
    public CollectReturn getOrderList(@PathVariable(name = "page") Integer page, @PathVariable(name = "limit") Integer limit, HttpServletRequest request){
        String token = request.getHeader("token");
        return collectService.getOrderList(page,limit,token);
    }
    @ApiOperation("删除收藏中商品")
    @GetMapping("/api/collect/{collectId}")
    public String deleteCollect(@PathVariable(name = "collectId") Integer collectId){
        return collectService.deleteCollect(collectId);
    }
    @ApiOperation("提交购物车中选中商品到收藏")
    @GetMapping("/api/collect/cart")
    public String insertOrder(HttpServletRequest request){
        String token = request.getHeader("token");
        return collectService.insertOrder(token);
    }
}
